package fr.cephb.joperon.webapp.beans;

import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;

import fr.cephb.joperon.core.Operon;
import fr.cephb.joperon.core.db.MPanelDB;
import fr.cephb.joperon.core.entities.MPanel;


public class MPanelBean
extends MPanel
{
private static final long serialVersionUID = 1L;
private boolean isnew=true;

public MPanelBean()
	{
	}

public MPanelBean(MPanel cp)
	{
	super(cp);
	}


public void setNew(boolean isnew) {
	this.isnew = isnew;
	}

public boolean isNew()
	{
	return isnew;
	}

public String getCommandName()
	{
	return isNew()?"Create":"Update";
	}

public String JsfAction()
	{
	FacesContext ctx= FacesContext.getCurrentInstance();
	ExternalContext ec = ctx.getExternalContext();
	//Application ap=ctx.getApplication();
	
	Object operon=ec.getApplicationMap().get("operon");
	if(operon!=null)
		{
		
		try {
			MPanelDB db= new MPanelDB(Operon.class.cast(operon));
			db.open();
			if(isNew()) setUid(-1);	
			{
				//db.put(new UInt32(getUid()),this);
			}
				
			db.close();
			} catch
		(Exception e) {
			e.printStackTrace();
			}
		return "ok";
		}
	System.err.println("Returning null operon="+operon);
	return null;
	}


}
